package com.yuanqi.repository;

import com.yuanqi.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

    /**
     * 根据用户名查找用户
     */
    Optional<User> findByUsername(String username);

    /**
     * 根据用户名查找启用的用户
     */
    @Query("SELECT u FROM User u WHERE u.username = :username AND u.status = 1 AND u.deletedAt IS NULL")
    Optional<User> findActiveUserByUsername(@Param("username") String username);

    /**
     * 检查用户名是否存在
     */
    boolean existsByUsername(String username);
}


